import datetime
from applications.extensions import db
import pytz


# 公众号
class Weixin_Official_Acc(db.Model):
    __tablename__ = 't_weixin_official_acc'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='公众号ID')
    wx_name = db.Column(db.String(35), comment='公众号名称', unique=True, nullable=False)
    wx_code = db.Column(db.String(35), comment='公众号微信号')
    wx_group_code = db.Column(db.String(35), comment='公众号区域分组CODE')
    enable = db.Column(db.Integer, default=0, comment='启用')
    avatar = db.Column(db.String(255), comment='头像', default="/static/admin/admin/images/avatar.jpg")
    remark = db.Column(db.String(255), comment='备注')
    article_nu = db.Column(db.Integer, comment='文章数量', default=0)
    create_at = db.Column(db.DateTime(timezone=True), default=datetime.datetime.now,
                          comment='创建时间')
    update_at = db.Column(db.DateTime(timezone=True), comment='更新时间')
    robot_id = db.Column(db.Integer, comment='采集机器人ID')


# 公众号分组
class Weixin_Official_Acc_Group(db.Model):
    __tablename__ = 't_weixin_group'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='分组ID')
    name = db.Column(db.String(35), comment='公众号区域分组名称', unique=True, nullable=False)
    code = db.Column(db.String(35), comment='公众号区域分组CODE', unique=True)


# 微信号采集日志
class Weixin_Official_Acc_log(db.Model):
    __tablename__ = 't_weixin_official_acc_log'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='采集流水ID')
    wx_id = db.Column(db.Integer, db.ForeignKey('t_weixin_official_acc.id'), comment='公众号id')
    robot_id = db.Column(db.Integer, db.ForeignKey('t_robot_info.id'), comment='机器人ID')
    article_nu = db.Column(db.Integer, default=0, comment='文章数量')
    indb_nu = db.Column(db.Integer, default=0, comment='文章入库数量')
    elapsed_time = db.Column(db.Integer, default=0, comment='耗时-单位是秒')
    year = db.Column(db.Integer, default=0, comment='年份')
    month = db.Column(db.Integer, default=0, comment='月份')
    day = db.Column(db.Date, comment='日')
    time = db.Column(db.Time, comment='时间记录')
    update_at = db.Column(db.DateTime(timezone=True), comment='更新时间')

#公众号及区域对应关系 中间表
class Weixin_Official_Acc_Group_ret(db.Model):
    __tablename__ = 't_weixin_official_acc_group'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='关联ID')
    wx_offac_id = db.Column(db.Integer, db.ForeignKey('t_weixin_official_acc.id'), comment='内部公众号id', nullable=False)
    group_id = db.Column(db.Integer, db.ForeignKey('t_weixin_group.id'), comment='区域分组id', nullable=False)



